//
//  PEHEBatTopoFullScreenVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/1/5.
//

#import "RHPlantInfoTopoFullScreenVC.h"
#import "RHPlantDetailModel.h"
#import "RHBatteryView.h"
#import "YYAnimatedImageView.h"
#import "YYImage.h"
#import "RHPlantTopoHEBATView.h"
#import "RHPlantTopoMEView.h"

@interface RHPlantInfoTopoFullScreenVC ()
@property (nonatomic, strong) RHPlantDetailModel *detailModel;

@property (nonatomic, strong) RHPlantTopoHEBATView *HE_topoView;

@property (nonatomic,strong) RHPlantTopoMEView *ME_topoView;
@end

@implementation RHPlantInfoTopoFullScreenVC

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];

}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:UIColor.whiteColor];
    [self.navigationController.view setBackgroundColor:UIColor.whiteColor];
    self.navigationItem.title = @"Full Chart";
    self.isUnPopGes = YES;
    [self getStationDetail];
    [self setupUI];
   
}


- (void)setupUI{
    kWeakSelf;
    self.view.backgroundColor = UIColor.whiteColor;
    self.bgView.clipsToBounds = NO;
  
    if(self.plantModel.productTypeId == ProductType_ME)
    {
        _ME_topoView = [[RHPlantTopoMEView alloc]initWithOrientation:YES];
        [self.bgView addSubview:_ME_topoView];
        [_ME_topoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_offset(0);
            make.top.offset(0);
        }];
    }
    if (self.plantModel.productTypeId == ProductType_HE_BAT||
        self.plantModel.productTypeId == ProductType_HE_ALLINONE) {
        _HE_topoView = [[RHPlantTopoHEBATView alloc]initWithOrientation:YES];
        [self.bgView addSubview:_HE_topoView];
        [_HE_topoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_offset(0);
            make.top.offset(0);
        }];
    }
    
    //全屏
   
    QMUIButton *fullBtn = [[QMUIButton alloc]init];
    [fullBtn setImage:[UIImage imageNamed:@"full_back"] forState:UIControlStateNormal];
    [self.bgView addSubview:fullBtn];
    [fullBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(35);
        make.top.mas_offset(10);
        make.right.mas_offset(-10);
    }];
    [[fullBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
           delegate.allowRotate = 0;
        if(@available(iOS 16.0, *)) {
            [weakSelf.navigationController setNeedsUpdateOfSupportedInterfaceOrientations];
            NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
            UIWindowScene *ws = (UIWindowScene *)array[0];
            UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
            geometryPreferences.interfaceOrientations = UIInterfaceOrientationMaskPortrait;
            [ws requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) {
                 //业务代码
            }];
        }else{
            NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
            [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
        }
        [weakSelf.navigationController popViewControllerAnimated:YES];
      
    }];
    
   
}




//光伏,馈网,电池,负载等数据
-(void)getStationDetail
{
    [RHPlantDetailModel startGetWithCompletionAPIKey:H_getStationDetail argument:@{@"plantId":@(self.plantModel.plant_id)} requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
            self.detailModel = resultModel.data;
            [self updateData];
        }
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
}

-(void)updateData
{
    
    if(self.plantModel.productTypeId == ProductType_ME)
    {
        [_ME_topoView setTopoModel:self.detailModel];
    }
    if (self.plantModel.productTypeId == ProductType_HE_BAT||
        self.plantModel.productTypeId == ProductType_HE_ALLINONE) {
        [_HE_topoView setTopoModel:self.detailModel deviceTypeCode:self.plantModel.deviceTypeCode];
    }
    
    
}



@end
